<?php
/**
 * Created by PhpStorm.
 * User: s.utkin
 * Date: 15.01.2015
 * Time: 19:41
 */

/**
 * @var $this \Pinenut\Action
 * @var $items array
 */

if (count($items) == 0) {
	return;
}

$htmlClass = isset($htmlOptions['class']) ? $htmlOptions['class'] : '';
$htmlId = isset($htmlOptions['id']) ? $htmlOptions['id'] : '';
$htmlStyle = isset($htmlOptions['style']) ? $htmlOptions['style'] : '';

$defaultContainerClass = isset($defaultContainerOptions['class']) ? $defaultContainerOptions['class'] : '';
$defaultContainerId = isset($defaultContainerOptions['id']) ? $defaultContainerOptions['id'] : '';
$defaultContainerStyle = isset($defaultContainerOptions['style']) ? $defaultContainerOptions['style'] : '';

$defaultLinkClass = isset($defaultLinkOptions['class']) ? $defaultLinkOptions['class'] : '';
$defaultLinkId = isset($defaultLinkOptions['id']) ? $defaultLinkOptions['id'] : '';
$defaultLinkStyle = isset($defaultLinkOptions['style']) ? $defaultLinkOptions['style'] : '';

?>
<ul<?php if ($htmlId) : ?> id="<?php echo $htmlId; ?>"<?php endif; ?><?php if ($htmlClass) : ?> class="<?php echo $htmlClass; ?>"<?php endif; ?><?php if ($htmlStyle) : ?> style="<?php echo $htmlStyle; ?>"<?php endif; ?>>
	<?php foreach ($items as $item) : ?>
		<?php
			if (isset($item['actionContent'])) {
				echo $item['actionContent'];
				continue;
			}
		?>
		<?php

			$containerClass = isset($item['containerOptions']['class']) ? $item['containerOptions']['class'] : $defaultContainerClass;
			$containerClass .= isset($item['selected']) && $item['selected'] ? ' selected' : '';
			$containerId = isset($item['containerOptions']['id']) ? $item['containerOptions']['id'] : $defaultContainerId;
			$containerStyle = isset($item['containerOptions']['style']) ? $item['containerOptions']['style'] : $defaultContainerStyle;

			$linkClass = isset($item['linkOptions']['class']) ? $item['linkOptions']['class'] : $defaultLinkClass;
			$linkId = isset($item['linkOptions']['id']) ? $item['linkOptions']['id'] : $defaultLinkId;
			$linkStyle = isset($item['linkOptions']['style']) ? $item['linkOptions']['style'] : $defaultLinkStyle;

			$url = is_array($item['action']) ?
				$this->url($item['action']['name'], $item['action']['params']) :
				$this->url($item['action']);
			$nestedMenu = isset($item['nestedMenu']) ? $item['nestedMenu'] : '';
		?>
		<li<?php if ($containerId) : ?> id="<?php echo $containerId; ?>"<?php endif; ?><?php if ($containerClass) : ?> class="<?php echo $containerClass; ?>"<?php endif; ?><?php if ($containerStyle) : ?> style="<?php echo $containerStyle; ?>"<?php endif; ?>><a href="<?php echo $url; ?>" <?php if ($linkId) : ?> id="<?php echo $linkId; ?>"<?php endif; ?><?php if ($linkClass) : ?> class="<?php echo $linkClass; ?>"<?php endif; ?><?php if ($linkStyle) : ?> style="<?php echo $linkStyle; ?>"<?php endif; ?>><?php echo $item['title']; ?></a><?php echo $nestedMenu; ?></li>
	<?php endforeach;?>
</ul>
